/*
 * thread_pool.h
 *
 *  Created on: 2008-12-15
 *      Author: fanliangliang
 */

#ifndef THREAD_POOL_H_
#define THREAD_POOL_H_

#include "safe_queue.h"
#include <vector>

BEGIN_NAMESPACE_TOXIC

class ThreadPool {
	CLASS_UNCOPYABLE(ThreadPool)
public:
	explicit ThreadPool(size_t size);
	~ThreadPool();

	template <typename T>
	void schedule(const T& op) {
		_queue.push(toxic::detail::transform(op));
	}

	void wait();

private:
	void work();

private:
	std::vector<Thread*> _threads;
	safe_queue<Runnable*> _queue;
};

END_NAMESPACE_TOXIC

#endif /* THREAD_POOL_H_ */
